package com.leet.twopoint;

import java.util.List;

public class DeleteCharFindLongest {
    public String findLongestWord(String s, List<String> dictionary) {
        String ans = "";
        for(String word:dictionary){
            if(cmp(s,word)){
                if((word.length() > ans.length())||(word.length() == ans.length() && word.compareTo(ans) < 0)){
                    ans = word;
                }
            }
        }
        return ans;
    }
    public boolean cmp(String s1,String s2){
        int len1 = s1.length();
        int len2 = s2.length();
        int i = 0, j = 0;
        while(i < len1 && j < len2){
            if(s1.charAt(i) == s2.charAt(j)){
                i++;
                j++;
            }
            i++;
        }
        if(j == len2){
            return true;
        }
        return false;
    }
}
